package com.lxujia.ruankao.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ExecutorsUtil {
    private final static String TAG = "ExecutorsUtil";
    private static ExecutorsUtil mInstance;
    /** 每次只执行一个任务的线程池 */
    private static ExecutorService mCachedThreadExecutor = null;

    private ExecutorsUtil() {
        mCachedThreadExecutor = Executors.newCachedThreadPool();
    }

    public static ExecutorsUtil getInstance() {
        if (mInstance == null) {
            mInstance = new ExecutorsUtil();
        }
        return mInstance;
    }

    public void execute(Runnable runnable) {
        if (mCachedThreadExecutor == null || runnable == null) {
            LogUtil.d(TAG, "mCachedThreadExecutor or runnable is null");
            return;
        }
        mCachedThreadExecutor.execute(runnable);
    }

    public Future<?> submit(Runnable runnable) {
        if (mCachedThreadExecutor == null || runnable == null) {
            LogUtil.d(TAG, "mCachedThreadExecutor or runnable is null");
            return null;
        }
        return mCachedThreadExecutor.submit(runnable);
    }
}
